{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "--------------\n",
    "\n",
    "* 本学习记录人：许智超\n",
    "* 学习时间：2021-11-16\n",
    "* week11\n",
    "* 参考的文档：\n",
    "> 1. [python官方文档](https://python.org/doc)\n",
    "> 2. [许老师博客](https://cnblogs.com/xuzhichao)\n",
    "\n",
    "----------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 本周学习内容\n",
    "\n",
    "### 1. 认识列表(序列数据)\n",
    "\n",
    "### 2. 列表的取值（index）和切片（slice）\n",
    "\n",
    "### 3. 列表的一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 认识[列表list](https://docs.python.org/3/tutorial/introduction.html#lists)\n",
    "\n",
    "* 最通用的是list，它可以写成方括号之间以逗号分隔的值（项）的列表。列表可能包含不同类型的数据，但通常这些数据都具有相同的类型\n",
    "\n",
    "> 1. 列表的形式：括号之间以逗号分隔的值: [value1,value2,value3,...]\n",
    "> 2. 列表可以 索引（index） 和 切片（slice）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 思考： 如果我想存一些（一个班、一堆用户的名字），怎么存？\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Xiaofeng'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用字符串来存(操作起来--非常之不方便)\n",
    "stu_names = \"Ziqi|Xiaofeng|Lihua\"\n",
    "stu_names[5:13]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Xiaofeng'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_names_list = [\"Ziqi\",\"Xiaofeng\",\"Lihua\"]\n",
    "stu_names_list[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 列表的取值（index）和切片（slice）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "         0       1        2      3\n",
    "        -4       -3      -2      -1\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Marry', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 1. 取值 按照索引index 取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jan Marry\n"
     ]
    }
   ],
   "source": [
    "print(names[2],names[-3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 2. 切片 slice\n",
    ">> 1. letters[start:stop:step]\n",
    ">> 2. 如果没有指定开始值，则默认为0；\n",
    ">> 3. 如果没有指定结束指，则取列表允许的最大值；\n",
    ">> 4. 如果没有指定步长值，则默认步长为1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 列表的方法（一般方法）\n",
    "\n",
    "> 1. 列表的增加\n",
    "> 2. 列表的删除\n",
    "> 3. 列表的修改\n",
    "> 4. 列表的查询（如上 取值和切片）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Marry', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(...) method of builtins.list instance\n",
      "    L.append(object) -> None -- append object to end\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)\n",
    "# 因为列表可以存不同类型的数据（object），增加一个object到列表末尾"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 1. 列表的增加\n",
    ">> 1. append()--> L(list).append(object) --> None -- append object to end\n",
    ">> 2. insert()-->  L.insert(index, object) --> insert object before index\n",
    "\n",
    "|序号| 列表的方法 | 用法  | details |\n",
    "|----| ---- | ---- |---- |\n",
    "|1| append()  |  L(list).append(object)  |  None -- append object to end  |\n",
    "|2| insert()  |  L.insert(index, object) |  insert object before index  |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'Lihua']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Xiaoming\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'Lihua', 'Xiaoming']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(...) method of builtins.list instance\n",
      "    L.insert(index, object) -- insert object before index\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(2,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Alex', 'Jan', 'Jack', 'Lihua', 'Xiaoming']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 2. 列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "names."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
